package com.zbkj.front.controller.merchant.monitor;

import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.model.merchant.Merchant;
import com.zbkj.common.model.monitor.ZfbMonitorDeviceBind;
import com.zbkj.common.model.monitor.ZfbMonitorOrder;
import com.zbkj.common.request.ZfbMonitorDeviceBindRequest;
import com.zbkj.common.request.ZfbMonitorDeviceUnbindRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.MerchantService;
import com.zbkj.service.service.UserService;
import com.zbkj.service.service.ZfbMonitorDeviceBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 蓝牙网关（发射器）管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/front/merchant/monitor/device/bind")
@Api(tags = "蓝牙网关（发射器）管理", description = "蓝牙网关（发射器）管理") //配合swagger使用

public class ZfbMonitorDeviceBindController {

    @Autowired
    private ZfbMonitorDeviceBindService zfbMonitorDeviceBindService;

    @Autowired
    private UserService userService;

    /**
     * 绑定蓝牙网关到监控上
     * @param zfbMonitorDeviceBindRequest 新增参数
     * @author dazongzi
     * @since 2025-06-09
     */
    @ApiOperation(value = "绑定蓝牙网关到监控上")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<String> add(@RequestBody @Validated ZfbMonitorDeviceBindRequest zfbMonitorDeviceBindRequest) {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();
        if (zfbMonitorDeviceBindService.bindDeviceToMonitor(zfbMonitorDeviceBindRequest, systemAdmin.getMerId())) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 解绑蓝牙设备
     * @param zfbMonitorDeviceBindRequest Integer
     * @author dazongzi
     * @since 2025-06-09
     */
    @ApiOperation(value = "解绑蓝牙设备")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public CommonResult<String> delete(@RequestBody @Validated ZfbMonitorDeviceUnbindRequest zfbMonitorDeviceBindRequest) {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();
        if(zfbMonitorDeviceBindService.unbind(zfbMonitorDeviceBindRequest, systemAdmin.getMerId())) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }


}



